package com.sunzhuo.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Environment;

public class Save2Contents {

	public static void save2SD(String user, String passwd) throws IOException {
		File externalStorageDirectory = new File(
				Environment.getExternalStorageDirectory(), "pwd.txt");
		FileOutputStream fos = new FileOutputStream(externalStorageDirectory);
		String s = user + ":" + passwd;
		fos.write(s.getBytes());
		fos.flush();
		fos.close();
	}

	public static void save2ROM(Context context, String key, String passwd)
			throws IOException {
		File externalStorageDirectory = new File(context.getFilesDir(),
				"pwd.txt");
		FileOutputStream fos = new FileOutputStream(externalStorageDirectory);
		String s = key + ":" + passwd;
		fos.write(s.getBytes());
		fos.flush();
		fos.close();
	}

	public static void save2SH(Context context, String xingZuoId, String dateId)
			throws IOException {
		SharedPreferences sp = context.getSharedPreferences("XingZuo",Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putString("xingZuoId",xingZuoId);
		edit.putString("dateId",dateId);		
		edit.commit();

	}

	public static Map<String, String> readFromSP(Context context) {
		SharedPreferences sp = context.getSharedPreferences("XingZuo",Context.MODE_PRIVATE);
		Map<String, String> all = (Map<String, String>) sp.getAll();
		return all;
	}
	
}
